package object;


public class TestObject {

    public static void main(String[] args) {
        generalPiece();
        new Person();
        new Person();

        System.out.println("--start--");
        new TestObject();
        new TestObject();
        System.out.println("--end--");
    }

    {
        System.out.println("1.Test的构造块");
    }

    public TestObject() {
        System.out.println("2.Test的构造方法");
    }

    static {
        System.out.println("3.TestObject的静态块");
    }


    /**
     * 普通代码块
     */
    public static void generalPiece() {
        { //直接使用{}定义，普通方法块
            int x = 10;
            System.out.println("x = " + x);
        }
        int x = 100;
        System.out.println("x = " + x);
    }

}

/**
 * 构造块
 */
class Person {
    { //定义在类中，不加任何修饰符，构造块
        System.out.println("1.Person类的构造块");
    }

    public Person() {
        System.out.println("2.Person类的构造方法");
    }

    static { //定义在非主类中的静态块
        System.out.println("3.Person类的静态块");
    }
}